import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'login_controller.dart';
import 'view/account_login_view.dart';
import 'view/sms_login_view.dart';

class LoginPage extends GetView<LoginController> {
  @override
  Widget build(BuildContext context) {
    ScreenHelper.init(context);
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.only(
            left: ScreenHelper.width(15),
            right: ScreenHelper.width(15),
            top: ScreenHelper.topSafeHeight + ScreenHelper.height(40)),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Image.asset(
              "assets/sign/logo.png",
              width: ScreenHelper.width(100),
              height: ScreenHelper.width(100),
              package: "basic_common",
            ),
            SizedBox(
              height: ScreenHelper.height(20),
            ),
            Text(
              "欢迎使用家庭服务医生端",
              style: TextStyle(
                  color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(16)),
              textAlign: TextAlign.center,
            ),
            SizedBox(
              height: ScreenHelper.height(20),
            ),
            Obx(() => controller.isAccountLogin.value
                ? AccountLoginView()
                : SmsLoginView()),
            Obx(
              () => agreementWidget(controller.isRead.value, onChange: (value) {
                controller.isRead.value = value!;
              }),
            ),
            Spacer(),
            bootomWidget(),
            SizedBox(
              height: ScreenHelper.height(40),
            )
          ],
        ),
      ),
    );
  }

  /// 底部 登录方式
  Widget bootomWidget() {
    return Align(
      alignment: Alignment.bottomCenter,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          SizedBox(
            height: ScreenHelper.height(44),
            child: Text.rich(
              TextSpan(
                  style: TextStyle(
                      fontSize: ScreenHelper.sp(14),
                      color: AppTheme.weakTextColor,
                      height: 2.0),
                  children: [
                    const TextSpan(
                      text: "暂无账号，",
                    ),
                    textLink("立即注册", type: 2, onTap: () {
                      // Get.toNamed(AppRoutes.regist);
                      RouterManager().navToRegister();
                    }),
                  ]),
              textAlign: TextAlign.left,
            ),
          ),
          SizedBox(
            height: ScreenHelper.height(20),
          ),
          Align(
            alignment: Alignment.bottomCenter,
            child: Text("其他登录方式",
                style: TextStyle(
                    color: AppTheme.seconddarkWeakTextColor,
                    fontSize: ScreenHelper.sp(12))),
          ),
          SizedBox(
            height: ScreenHelper.height(20),
          ),
          SizedBox(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                GestureDetector(
                  onTap: () {
                    controller.switchType();
                  },
                  child: Obx(() => !controller.isAccountLogin.value
                      ? buildTopImgItem(
                          icon: 'assets/sign/icon_account_login.png',
                          title: '密码登录',
                          packageName: "basic_common",
                          width: 37)
                      : buildTopImgItem(
                          icon: 'assets/sign/icon_sms.png',
                          title: '短信登录',
                          packageName: "basic_common",
                          width: 37)),
                ),
                // SizedBox(
                //   width: ScreenHelper.width(70),
                // ),
                // GestureDetector(
                //   onTap: () {
                //     controller.getAccountList();
                //   },
                //   child: buildTopImgItem(
                //       icon: 'assets/sign/icon_sign_login.png',
                //       title: '签名登录',
                //       packageName: "basic_common",
                //       width: 37),
                // ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
